<?php

use Illuminate\Support\Facades\Route;
use Vinlon\Laravel\LayAdmin\AdminResponse;

// AgentAdmin后台入口
Route::get('/' . config('lay-agent-admin.route_prefix'), 'AuthController@home');

// 编辑器图片上传(需要按照指定格式返回）
Route::post('editor/images', 'CommonController@uploadEditorImages');
Route::post('editor/video', 'CommonController@uploadEditorVideo');

Route::prefix('agent-admin')
    ->middleware(array_merge([
        AdminResponse::class,
    ], config('lay-agent-admin.middleware', [])))
    ->group(function () {
        // 获取图片验证码
        Route::get('captcha', 'AuthController@captcha');
        // 用户名密码登录
        Route::post('password_login_captcha', 'AuthController@passwordLoginWithCaptcha');
        // 重置密码
        Route::post('reset_password', 'AuthController@resetPasswordByEmail');
        Route::post('rights_entity_apply/import', 'RightsEntityController@import');

        // 渠道数据看板（临时）
        Route::get('channel_user_summary', 'ChannelDashboardController@listChannelUsers');
        Route::get('channel_summary', 'ChannelDashboardController@listChannels');

        Route::middleware(['auth:agent-admin'])->group(function () {
            Route::get('profile', 'AuthController@profile');
            Route::post('profile', 'AuthController@updateProfile');
            Route::post('changePassword', 'AuthController@changePassword');
            Route::get('qrcode', 'AuthController@qrcodeInit');

            // 菜单管理
            Route::get('sidebar', 'MenuController@sidebar');
            Route::get('menuTree', 'MenuController@getMenuTree');

            // 门店
            Route::resource('stores', 'StoreController')->only(['index', 'store', 'destroy']);

            // 用户
            Route::get('users', 'UserController@listUsers');
            Route::post('fontendusers/export', 'UserController@export'); // 用户导出
            Route::post('users/{id}/punish_config', 'UserController@punish_config');
            Route::post('users/{id}/unpunish_config', 'UserController@unpunish_config');
            Route::post('users/{id}/asset_export', 'UserController@exportAssets');
            Route::post('users/{id}/source', 'UserController@updateSource');

            // 渠道商
            Route::get('channels', 'ChannelController@index');
            Route::get('channels/target/{id}', 'ChannelController@target');
            Route::get('channels/simple', 'ChannelController@listSimpleChannels');
            Route::post('channel/create', 'ChannelController@store');
            Route::post('channel/userexport', 'ChannelController@userexport');
            Route::post('channel/orderexport', 'ChannelController@orderexport');

            // 用户登录历史
            Route::get('user_login_history', 'UserController@loginHistory');
            Route::post('user_login_history/export', 'UserController@loginHistoryExport');

            // 商品导出
            Route::post('export/products', 'ProductController@export');
            // 订单导出
            Route::post('orders/export', 'OrderController@export');

            // 商品
            Route::get('products', 'ProductController@listProducts');
            Route::post('products/image', 'ProductController@uploadProductImage');
            Route::get('resale_products', 'ProductController@listResaleProducts');
            Route::get('products/{id}', 'ProductController@getProduct');
            Route::get('products/{id}/tokens', 'ProductController@listProductTokens');
            Route::post('products/{id}/edit', 'ProductController@editProduct');
            Route::post('products/{id}/resale_config', 'ProductController@saveResaleConfig');
            Route::post('products/{id}/exchange_config', 'ProductController@saveExchangeConfig');
            Route::post('products/{id}/asset_key_set', 'ProductController@assetKeyset');
            Route::post('products/{id}/release', 'ProductController@releaseProduct');
            Route::post('products/{id}/offline', 'ProductController@offlineProduct');
            Route::get('product_token_evidence/{product_token_id}', 'ProductController@getTokenEvidence');
            Route::get('blind_boxes', 'ProductController@listBlindBoxes');
            Route::get('export_product_holders', 'ProductController@exportProductHolders');
            Route::get('export_product_tokens', 'ProductController@exportProductTokens');

            // 转赠记录
            Route::get('asset/give_records', 'AssetController@giveRecords');
            // 转赠记录导出
            Route::post('asset/give_records/export', 'AssetController@giveRecordsExport');

            //提前购
            Route::get('products/{id}/early_buy', 'EarlyBuyController@getEarlyBuyWhiteList');
            Route::post('products/{id}/early_buy', 'EarlyBuyController@save');
            Route::post('products/{id}/early_buy/upload', 'EarlyBuyController@uploadFile');

            // 肓盒商品
            Route::get('blind_box/available_products', 'BlindBoxController@listAvailableProducts');
            Route::post('blind_box/queue', 'BlindBoxController@generateProductQueue');
            Route::post('blind_boxes', 'BlindBoxController@createBlindBox');
            Route::get('blind_boxes/{id}/products', 'BlindBoxController@listProductsInBlindBox');
            Route::get('blind_boxes/{id}/items', 'BlindBoxController@listBlindBoxItems');
            Route::post('blind_boxes/{id}/online', 'BlindBoxController@online');
            Route::post('blind_boxes/{id}/offline', 'BlindBoxController@offline');
            Route::post('blind_boxes/{id}/stop', 'BlindBoxController@stop');
            Route::post('blind_boxes/{id}/basic', 'BlindBoxController@editBasicInfo');

            // 商品品类
            Route::get('product_categories', 'ProductController@categoryTree');
            Route::post('product_categories', 'ProductController@saveCategories');

            // 实物商品
            Route::get('rights_entities', 'RightsEntityController@list');
            Route::post('rights_entities', 'RightsEntityController@store');
            Route::delete('rights_entities/{id}', 'RightsEntityController@destroy');
            Route::post('rights_entities/{id}/pause', 'RightsEntityController@pauseEntity');
            Route::post('rights_entities/{id}/sale', 'RightsEntityController@saleEntity');

            Route::get('rights_entity_apply', 'RightsEntityController@applyRecords');
            Route::post('rights_entity_apply', 'RightsEntityController@editApplyRecords');
            Route::post('rights_entity_apply/export', 'RightsEntityController@applyExport');
            Route::post('rights_entity_apply/batch', 'RightsEntityController@batchEditApplyRecords');

            // 订单
            Route::get('orders', 'OrderController@listOrders');
            Route::get('resale_orders', 'OrderController@listResaleOrders');
            Route::get('blind_box_orders', 'OrderController@listBlindBoxOrders');
            Route::get('orders/{id}', 'OrderController@getOrder');
            Route::post('orders/{id}/re_transfer', 'OrderController@reTransfer');

            Route::post('resale/export', 'OrderController@resaleExport');
            Route::post('blind/export', 'OrderController@blindExport');
            Route::get('agent_amount', 'OrderController@getAgentOrderCharge');

            // 权益
            Route::get('products_with_entity_rights', 'RightsController@listProductsWithEntityRights');
            Route::post('export_product_buyers', 'RightsController@exportProductBuyers');
            Route::get('asset_keys', 'AssetKeyController@index');

            //邀请活动
            Route::get('invites', 'InvitationActivityController@listInvites');
            Route::post('invites/create', 'InvitationActivityController@createInvites');
            Route::get('invites/{id}', 'InvitationActivityController@getInvitesDetail');
            Route::delete('invite/{id}', 'InvitationActivityController@deleteInvitesDetail');
            Route::get('invites_ranking', 'InvitationActivityController@getInvitesDetails');
            Route::post('invite/change_no', 'InvitationActivityController@changeInvitesStatusNo');
            Route::post('invite/change_yes', 'InvitationActivityController@changeInvitesStatusYes');
            Route::post('invite/activity_close', 'InvitationActivityController@changeActivityStatusClose');
            Route::post('invite/activity_open', 'InvitationActivityController@changeActivityStatusOpen');
            Route::get('invites/{activity_id}/registers_export', 'InvitationActivityController@exportRegisters');
            Route::post('invites/{activity_id}/registers/{register_id}/invited_users_export', 'InvitationActivityController@exportInvitedUsers');

            // 合成
            Route::get('convert_formulas', 'ConvertController@listFormulas');
            Route::get('convert_formulas/{id}', 'ConvertController@getFormula');
            Route::post('convert_formulas', 'ConvertController@saveFormula');
            Route::post('convert_formulas/{id}/status', 'ConvertController@changeStatus');
            Route::get('convert_formulas/{id}/records', 'ConvertController@listRecords');
            Route::get('convert_formulas/{id}/records_export', 'ConvertController@exportRecords');

            // 空投
            Route::get('airdrops', 'AirdropController@index');
            Route::post('airdrops/store', 'AirdropController@store');
            Route::post('airdrops/{id}/reissue', 'BlindBoxController@reissue');
            Route::post('airdrops/export', 'AirdropController@export');
            Route::post('airdrops/import', 'AirdropController@import');
            // 盲盒空投
            Route::post('airdrops/blind_box/store', 'AirdropController@storeBlindBoxAirdrop');

            // 版权登记
            Route::resource('registries', 'RegistryController')->only(['index', 'show']);
            Route::get('registry/price_setting', 'RegistryController@getPriceSettings');
            Route::post('registry/price_setting', 'RegistryController@savePriceSettings');

            // 运维设置
            Route::get('settings', 'CommonController@listAgentSettings');
            Route::post('settings', 'CommonController@saveAgentSettings');
            Route::post('settings/website_logo', 'CommonController@uploadWebsiteLogo');
            Route::post('banners/image', 'BannerController@uploadImage');
            Route::resource('banners', 'BannerController')->only(['index', 'store', 'destroy']);
            Route::get('downloads', 'DownloadController@index');

            //消息
            # 站内信
            Route::get('message_templates', 'MessageController@listTemplates');
            Route::post('message_templates', 'MessageController@saveTemplate');
            Route::delete('message_templates/{id}', 'MessageController@deleteTemplate');
            Route::post('upload_receivers', 'MessageController@uploadReceivers');
            # 系统公告
            Route::post('notices/image', 'NoticeController@uploadImage');
            Route::resource('notices', 'NoticeController')->only(['index', 'store', 'destroy']);

            //抽奖
            Route::resource('lotteries', 'LotteryController')->only(['index', 'show', 'store', 'destroy']);
            Route::post('lotteries/{id}/open', 'LotteryController@open');
            Route::post('lotteries/{id}/close', 'LotteryController@close');
            Route::get('lotteries/{id}/awards', 'LotteryController@listAwards');
            Route::post('lotteries/award_image', 'LotteryController@uploadAwardImage');
            Route::post('lotteries/{id}/import_users', 'LotteryUserController@batchImport');
            Route::post('lotteries/{id}/import_delivery', 'LotteryRecordController@batchUpdateDelivery');
            Route::resource('lottery_users', 'LotteryUserController')->only(['index', 'store', 'destroy']);
            Route::get('lottery_records', 'LotteryRecordController@index');
            Route::post('lottery_records/{id}/deliver', 'LotteryRecordController@deliver');
            Route::post('lottery_records/export', 'LotteryRecordController@exportRecords');

            //运营支持
            Route::get('business/resale_products', 'BusinessController@listResaleProducts');
            Route::post('business/lock_resale_products', 'BusinessController@lockResaleProducts');
            Route::get('business/locked_orders', 'BusinessController@listLockedOrders');
            Route::post('business/batch_unlock', 'BusinessController@batchUnLock');
            Route::post('business/merge_pay', 'BusinessController@mergePay');
            Route::post('business/cancel_merge_pay', 'BusinessController@cancelMergePay');
            Route::get('business/user_assets', 'BusinessController@listUserAssets');
            Route::get('business/user_asset_tokens', 'BusinessController@listUserAssetTokens');
            Route::post('business/batch_resale', 'BusinessController@batchResale');
            Route::post('business/batch_cancel_resale', 'BusinessController@batchCancelResale');
            Route::resource('business/auto_lock_task', 'AutoLockTaskController')->only(['index', 'store', 'destroy']);
        });
    });
